<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Table</title>
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/addons/hc_answer/template/css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="/addons/hc_answer/template/plugins/font-awesome/css/font-awesome.css">
		<link rel="stylesheet" href="/addons/hc_answer/template/css/table.css" />
	</head>
	<body>
		<div class="admin-main">

			<blockquote class="layui-elem-quote">
				<a href="javascript:;" class="layui-btn layui-btn-small" id="add">
					<i class="layui-icon">&#xe608;</i> 添加分类
				</a>
				<a href="javascript:;" class="layui-btn layui-btn-small" id="refresh">
					<i class="layui-icon">&#x1002;</i> 刷新
				</a>
			</blockquote>
			<fieldset class="layui-elem-field">
				<legend>分类列表</legend>
				<div class="layui-field-box">
					<table class="site-table table-hover">
						<thead>
							<tr>
								<th>所属分类</th>
								<th>分类名称</th>
								<th>分类图片</th>
								<th>创建时间</th>
								<th>排序</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>

				</div>
			</fieldset>
			<div class="admin-table-page">
				<div id="page" class="page">
				</div>
			</div>
		</div>
		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>
		<script>
			layui.config({
				base: '/addons/hc_answer/template/plugins/layui/modules/'
			});

			layui.use(['icheck', 'laypage','layer'], function() {
				var $ = layui.jquery,
					laypage = layui.laypage,
					layer = parent.layer === undefined ? layui.layer : parent.layer;
				$('input').iCheck({
					checkboxClass: 'icheckbox_flat-green'
				});

				//page
				laypage({
					cont: 'page',
					pages: {$nums},
					groups: 10,
					jump: function(obj, first) {
						//得到了当前页，用于向服务端请求对应数据
						var curr = obj.curr;
						var html ='';
						$.ajax({
				            url:"{php echo $this->createWebUrl('categoryajax');php}",
				            data:{page:curr},
				            type:"post",
				            dataType:"json",
				            success:function(data){
				            	layui.each(data.data, function(index, item){
				            		html += '<tr>';
							      	html += '<td>'+item.pid+'</td>';
							      	html += '<td>'+item.name+'</td>';
							      	html += '<td><img src="'+item.thumbs+'" style="width:50px"></td>';
							      	html += '<td>'+item.createtime+'</td>';
							      	html += '<td>'+item.sort+'</td>';
							      	html += '<td><a href="javascript:;" class="layui-btn layui-btn-mini" data-id="'+item.id+'" id="edit">编辑</a>&nbsp;&nbsp;';
							      	html += '<a href="javascript:;" class="layui-btn layui-btn-mini" data-id="'+item.id+'" id="up">升级条件</a>&nbsp;&nbsp;';
							      	html += '<a href="javascript:;" data-id="'+item.id+'" id="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a></td>';
							      	html += '</tr>';
							    });
							    $("tbody").html(html);
				            },
				            error:function(data){
				                layer.alert('请稍后重试', {icon: 5});
				            }
				        });
						
					}
				});

				$('#search').on('click', function() {
					parent.layer.alert('你点击了搜索按钮')
				});
				$('#refresh').on('click', function() {
					location.reload();
				});
				$('#add').on('click', function() {
					layer.open({
					  type: 2,
					  area: ['900px', '650px'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=categoryadd&m=hc_answer',
					  end: function () {
				        location.reload();
				      }
					});
				});

				$('tbody').on('click', '#edit',function() {
					var id = $(this).attr('data-id');
					layer.open({
					  type: 2,
					  area: ['900px', '650px'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=categoryadd&m=hc_answer&id='+id,
					  end: function () {
				        location.reload();
				      }
					});
				});
				$('tbody').on('click', '#up',function() {
					var id = $(this).attr('data-id');
					layer.open({
					  type: 2,
					  area: ['75%', '90%'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=categoryup&m=hc_answer&id='+id,
					  end: function () {
				        location.reload();
				      }
					});
				});
				$('tbody').on('click', '#del',function() {
					var id = $(this).attr('data-id');
					layer.confirm('确定要删除吗，一经删除将会删除对应的题目？', {
						btn: ['确认','取消'],
						end: function () {
					        location.reload();
					      }
					}, function(){
						$.ajax({
				            url:"{php echo $this->createWebUrl('categorydo');php}",
				            data:{id:id,act:'del'},
				            type:"post",
				            dataType:"json",
				            success:function(data){
				            	if(data.code=='1'){
				                	layer.alert(data.msg, {icon: 6});
				            	}else{
				                	layer.alert(data.msg, {icon: 5});
				            	}
				            },
				            error:function(data){
				                layer.alert('请稍后重试', {icon: 5});
				            }
				        });
					});
				});
				

			});
		</script>
	</body>

</html>